package com.yrh.dao.impl;

import com.yrh.bean.TOrderDetails;
import com.yrh.dao.TOrderDetailsDao;
import com.yrh.utils.DataSourceUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
/*订单详细数据层接口实现类*/
public class TOrderDetailsDaoImpl implements TOrderDetailsDao {
    private JdbcTemplate temp=new JdbcTemplate(DataSourceUtil.getDataSource());
    @Override
    public List<TOrderDetails> byOrderId(int oId) {
        String sql="SELECT tod.`order_id`,tod.`product_num`,tod.`product_money`,tod.`product_name` \n" +
                "FROM t_order t,t_order_details tod\n" +
                "WHERE t.`order_id`=tod.`order_id` and t.order_id=?";
        Object[] objects=new Object[]{oId};
        return temp.query(sql,objects,new BeanPropertyRowMapper<>(TOrderDetails.class)) ;
    }
    //生成订单详情表
    @Override
    public int addOrderDetail(TOrderDetails orderDetails) {
        return temp.update("insert into t_order_details(product_name, product_num, product_money, order_id) values " +
                "(?,?,?,?)",orderDetails.getProductName(),orderDetails.getProductNum(),orderDetails.getProductMoney(),orderDetails.getOrderId());
    }
}
